package com.exp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.exp.dto.DocumentIUpdateDTO;
import com.exp.dto.DocumentPageQueryDTO;
import com.exp.interceptor.JwtTokenAdminInterceptor;
import com.exp.mapper.DocumentInfMapper;
import com.exp.pojo.NoticeInf;
import com.exp.pojo.UserInf;
import com.exp.result.PageResult;
import com.exp.service.DocumentInfService;
import com.exp.pojo.DocumentInf;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 王-自信
* @description 针对表【document_inf】的数据库操作Service实现
* @createDate 2024-11-18 20:52:04
*/
@Service
public class DocumentInfServiceImpl extends ServiceImpl<DocumentInfMapper, DocumentInf>
    implements DocumentInfService {

    @Autowired
    private DocumentInfMapper documentInfMapper;
    @Override
    public PageResult pageQuery(DocumentPageQueryDTO documentPageQueryDTO) {
        System.out.println("service:"+documentPageQueryDTO);
        // select * from employee limit 0,10
        PageHelper.startPage(documentPageQueryDTO.getPage(), documentPageQueryDTO.getPageSize());

        Page<DocumentInf> page = documentInfMapper.pageQuery(documentPageQueryDTO);

        long total = page.getTotal();

        List<DocumentInf> records = page.getResult();
        return new PageResult(total, records);
    }

    @Override
    public void update(DocumentIUpdateDTO documentIUpdateDTO) {
        DocumentInf documentInf = new DocumentInf();
        BeanUtils.copyProperties(documentIUpdateDTO, documentInf);
        // 从ThreadLocal中获取userId
        Integer userId = JwtTokenAdminInterceptor.threadLocal.get();
        if (userId != null) {
            // 使用userId进行操作
            documentInf.setUserId(userId);
        }
        documentInfMapper.update(documentInf);
    }


    @Override
    public void deleteBatch(List<Integer> ids) {
        //删除数据
        for (Integer id : ids) {
            documentInfMapper.deleteById(id);
        }
    }
}




